<?php
declare (strict_types=1);

// +----------------------------------------------------------------------
// | SCApi
// +----------------------------------------------------------------------
// | 版权所有 2021~2022 贾二小 [ http://www.ipsoul.com ]
// +----------------------------------------------------------------------
// | 官方网站: http://www.ipsoul.com
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// | 免费声明 ( http://doc.ipsoul.com/disclaimer )
// +----------------------------------------------------------------------
// | gitee 代码仓库：https://gitee.com/jiaerxiao/scapi
// | github 代码仓库：https://github.com/jiaerxiao/scapi
// +----------------------------------------------------------------------

namespace app\system\controller;

use app\common\controller\SystemBaseController;
use app\system\facade\MenuFacade;
use hg\apidoc\annotation\Group;
use hg\apidoc\annotation\Sort;
use hg\apidoc\annotation\Author;
use think\App;

/**
 * 菜单管理
 * @Group("System")
 * @Sort(5)
 */
class Menu extends SystemBaseController
{
    /**
     * 初始化
     */
    public function initialize()
    {
        $this->logName = "菜单管理";
        parent::initialize();
    }

    /**
     * 我的菜单列表
     * @Author("贾二小")
     * @since 2021/10/30
     */
    public function myList()
    {
        //获取数据
        $data = [];
        $data['menu'] = MenuFacade::myList();
        $data['permissions'] = [];
        //返回
        self::success($data);
    }

    /**
     * 菜单
     * @Author("贾二小")
     * @since 2021/11/23
     */
    public function list()
    {
        //获取数据
        $data = MenuFacade::tableList();
        //返回
        self::success($data);
    }

    /**
     * 菜单保存
     * @Author("贾二小")
     * @since 2021/12/20
     */
    public function saving()
    {
        //获取参数
        $paramData = $this->request->post(['id', 'parentId', 'name', 'path', 'redirect', 'component', 'active', 'meta', 'apiList']);
        //参数验证
        $this->validateData($paramData);
        //保存数据
        $data = MenuFacade::saving($paramData);
        //返回
        self::success($data);
    }
}